/**********************************************************************************************************************
 *
 * Project:    mGameEngine
 * File:       sphericaljoint.h
 * Author:     karooolek
 * Created on: Nov 14, 2009
 *
 **********************************************************************************************************************/

#ifndef SPHERICALJOINT_H_
#define SPHERICALJOINT_H_

#include "revolutejoint.h"

namespace mGameEngine
{
namespace Physics
{

/**
 * Spherical joint.
 * Spherical joint joins two points on different actors.
 * Any rotation around this points is allowed until limits are not specified.
 * Maximal twist is maximal rotation around joint anchor axis.
 * Maximal swing is maximal radial deviation from specified anchor axis.
 */
class SphericalJoint : public RevoluteJoint
{
protected:
    /**
     * Maximal joint swing.
     */
    float _maxSwing;

public:
    /**
     * Create spherical joint with specified anchor positions and axles.
     * @param point1 first anchor position.
     * @param point2 second anchor position
     * @param axis1 first anchor axis.
     * @param axis2 second anchor axis.
     * @param maxTwist maximal twist.
     * @param maxSwing maximal swing.
     */
    SphericalJoint(    const Vector3 &point1 = Vector3(),
                    const Vector3 &point2 = Vector3(),
                    const Vector3 &axis1 = Vector3(1.0f, 0.0f, 0.0f),
                    const Vector3 &axis2 = Vector3(-1.0f, 0.0f, 0.0f),
                    float maxTwist = M_PI, float maxSwing = M_PI);

    /**
     * Destroy spherical joint.
     */
    virtual ~SphericalJoint();

    /**
     * Get spherical joint maximal swing.
     * @return spherical joint maximal swing in radians.
     */
    float getMaximalSwing() const
    {
        return _maxSwing;
    }

    /**
     * Set spherical joint maximal swing.
     * @param maxSwing maximal swing in radians.
     */
    virtual void setMaximalSwing(float maxSwing);

    /**
     * Create PhysX spherical joint between two PhysX actors.
     * @param actor1 first PhysX actor.
     * @param actor2 second PhysX actor.
     */
    virtual void create(NxActor *actor1, NxActor *actor2) const;
};

}
}

#endif // SPHERICALJOINT_H_
